﻿@{  
    int rType = Convert.ToInt32(UrlData[0].ToLower());
    
   Dictionary<string,string> c = new Dictionary<string,string>();
        var custName = Request["custName"];
        var rBy = Request["rBy"];
        string custId = string.Empty;
        string rById = string.Empty;
        if(custName!=""){
           
            custId = UtilityManager.GetVal(Request["custId"]);
            if(custId==""){
                custId="0";
            }
        }
        
        if(rBy!=""){
            rById = UtilityManager.GetVal(Request["rById"]);
            if(rById==""){
                rById="0";
            }
        }
      
        if(custId!="0"){
            custName="";
        }
        c["FName"]=custName;
        //c["RefByName"]=rBy;
        c["CustomerID"]=custId;
        //c["CustomerID"]=UtilityManager.GetVal(Request["custId"]);
        c["CustomerStatus"]=UtilityManager.GetVal(Request["cStatus"]);
        c["CustomerClassification"]=UtilityManager.GetVal(Request["custClass"]);
        c["Region"]=UtilityManager.GetVal(Request["region"]);
        c["Solicitor"]=UtilityManager.GetVal(Request["solicitor"]);
        c["Campaign"]=UtilityManager.GetVal(Request["campaign"]);
        c["Country"]=UtilityManager.GetVal(Request["country"]);
        c["State"]=UtilityManager.GetVal(Request["state"]);
        c["RefBy"]=UtilityManager.GetVal(Request["rBy"]);
        c["CashCardNo"]=UtilityManager.GetVal(Request["ccno"]);
        c["CCStatus"]=UtilityManager.GetVal(Request["ccstatus"]);
        c["CCDelStatus"]=UtilityManager.GetVal(Request["delStatus"]);
        c["DocStatus"]=UtilityManager.GetVal(Request["docStatus"]);
        c["PartnerBank"]=UtilityManager.GetVal(Request["pb"]);
        c["DelCourier"]=UtilityManager.GetVal(Request["courier"]);
        c["DelCourier"]=UtilityManager.GetVal(Request["courier"]);
        c["CCSDateFrom"]=UtilityManager.GetVal(Request["from_ccsdate"]);
        c["CCSDateTo"]=UtilityManager.GetVal(Request["to_ccsdate"]);
        c["DelSDateFrom"]=UtilityManager.GetVal(Request["from_delsdate"]);
        c["DelSDateTo"]=UtilityManager.GetVal(Request["to_delsdate"]);
        c["DelDateFrom"]=UtilityManager.GetVal(Request["from_deldate"]);
        c["DelDateTo"]=UtilityManager.GetVal(Request["to_deldate"]);
        c["ExpDateFrom"]=UtilityManager.GetVal(Request["from_expdate"]);
        c["ExpDateTo"]=UtilityManager.GetVal(Request["to_expdate"]);
        c["AppDateFrom"]=UtilityManager.GetVal(Request["from_appdate"]);
        c["AppDateTo"]=UtilityManager.GetVal(Request["to_appdate"]);
        c["WithEmail"]=UtilityManager.GetVal(Request["email"]);
        c["WithLandLineNo"]=UtilityManager.GetVal(Request["landlineno"]);
        c["WithMobileNo"]=UtilityManager.GetVal(Request["mobileno"]);
        c["sort"]=UtilityManager.GetVal(Request["sort"]);
        c["sortdir"]=UtilityManager.GetVal(Request["sortdir"]);
        c["SrcRegion"]=UtilityManager.GetVal(Request["src_region"]);
        
        
   
    int reportType = Convert.ToInt32(Request["report"]);
    var reportData =  ReportManager.GetData(c,reportType);
    
    byte[] byteArray=null;
    DateTime today = DateTime.Today;
    //string ctr = UtilityManager.GetCounterForFileExt();
    string fileName=string.Empty;
    string path=string.Empty;
    
    try{
    
        switch(rType){
            case 1:
            path = "~/Content/Templates/ccmasterlist_template.xls";
            byteArray= UtilityManager.GenerateCCMasterListXL(Server.MapPath(path),"CCMasterList",reportData);
            fileName = string.Format("CashCardMasterListReport_{0}.xls",today.ToString("MM-dd-yyy"));
            break;
            case 2:
            path="~/Content/Templates/validationlist_template.xls";
            byteArray= UtilityManager.GenerateValidationListXL(Server.MapPath(path),"ValidationList",reportData);
            fileName = string.Format("ValidationListReport{0}.xls",today.ToString("MM-dd-yyy"));
            break;
            case 3:
            path="~/Content/Templates/pendingapplist_template.xls";
            byteArray= UtilityManager.GeneratePAListXL(Server.MapPath(path),"PendingAppList",reportData);
            fileName = string.Format("PendingAppListReport_{0}.xls",today.ToString("MM-dd-yyy"));
            break;
            case 4:
            path="~/Content/Templates/appinprogress_template.xls";
            byteArray= UtilityManager.GenerateAppInProgListXL(Server.MapPath(path),"AppInProgress",reportData);
            fileName = string.Format("ApplicationInProgressReport{0}.xls",today.ToString("MM-dd-yyy"));
            break;
          
            
        }
    }catch(Exception e){
        throw e;
    }
    
   
    
   
    //clear all content output from the buffer stream
    
    Response.Clear();
    //add HTTP Header to the output stream and speficy default name for the browser download dialog
    
    Response.AddHeader("Content-Disposition","attachment; filename="+fileName);
    //add header for file size
    Response.AddHeader("Content-Length",byteArray.Length.ToString());
    //set HTTP Mime Type
    Response.ContentType="application/vnd.ms-excel";
    //Write data to the client
    Response.BinaryWrite(byteArray);
    Response.Flush();
    Response.End();
 }    
